package edu.hm.compiler.parser.derive;

public class SimpleASTPrinter implements ASTPrinter
{
    private int count;

    /* (non-Javadoc)
     * @see edu.hm.compiler.parser.derive.ASTPrinter#inc()
     */
    @Override
    public void inc()
    {
        this.count++ ;
    }

    /* (non-Javadoc)
     * @see edu.hm.compiler.parser.derive.ASTPrinter#dec()
     */
    @Override
    public void dec()
    {
        this.count-- ;
    }

    /* (non-Javadoc)
     * @see edu.hm.compiler.parser.derive.ASTPrinter#out(java.lang.String)
     */
    @Override
    public void out( String string )
    {
        String[] split = string.split( "[\\r\\n]+" ); //$NON-NLS-1$
        String offset =""; //$NON-NLS-1$
        for( int i = 0; i < count; i++ )
        {
            offset +=" "; //$NON-NLS-1$
        }
        for( String s: split )
        {
            System.out.println( offset + s );
        }
        
    }

    /* (non-Javadoc)
     * @see edu.hm.compiler.parser.derive.ASTPrinter#err(java.lang.String)
     */
    @Override
    public void err( String string )
    {
        String[] split = string.split( "[\\r\\n]+" ); //$NON-NLS-1$
        String offset =""; //$NON-NLS-1$
        for( int i = 0; i < count; i++ )
        {
            offset +=" "; //$NON-NLS-1$
        }
        for( String s: split )
        {
            System.err.println( offset + s );
        }
    }

}
